package io.gitee.zhangbinhub.admin.route.domain

import io.gitee.zhangbinhub.acp.boot.interfaces.LogAdapter
import io.gitee.zhangbinhub.admin.route.entity.Route
import io.gitee.zhangbinhub.admin.route.repo.RouteRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
class InitDataDomain @Autowired constructor(
    private val logAdapter: LogAdapter,
    private val routeRepository: RouteRepository
) {
    companion object {
        const val WORK_FLOW_SERVER_API_ROUTE_ID = "workflow-server-api"
    }

    @Transactional
    fun doInitRoute() {
        routeRepository.save(
            Route(
                routeId = WORK_FLOW_SERVER_API_ROUTE_ID,
                enabled = true,
                orderNum = 0,
                uri = "lb://workflow-server",
                predicates = "[\"Path=/api/workflow/**\"]",
                filters = "[\"StripPrefix=1\"]",
                remarks = "工作流服务接口"
            )
        ).also { route ->
            logAdapter.info("Init Route ${route.remarks}[${route.routeId}]")
        }
    }
}